package com.studentexam.student.service.impl;

import com.studentexam.student.dao.ExamQuestionMapper;
import com.studentexam.student.dao.QuestionBankMapper;
import com.studentexam.student.eo.QuestionBankEoPage;
import com.studentexam.student.model.QuestionBank;
import com.studentexam.student.service.QuestionBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class QuestionBankServiceImpl implements QuestionBankService {
    @Autowired
    private QuestionBankMapper questionBankMapper;
    @Autowired
    private ExamQuestionMapper examQuestionMapper;



    @Override
    public int addQuestionBank(QuestionBank questionBank) {
        int returnInt=questionBankMapper.insertQuestionBank(questionBank);

        return returnInt;
    }

    @Override
    public int updateQuestionBank(QuestionBank questionBank) {
        int isUpdate=0;
        try{
            isUpdate=questionBankMapper.updateQuestionBank(questionBank);
        }catch (Exception e){
            isUpdate=-1;
            System.out.println("更新题库信息时执行sql报错原因为:"+e.getMessage());
        }
        return isUpdate;
    }

    @Override
    public int delQuestionBank(int questionbankid) {
        int returnDel=0;
        try {
            if (examQuestionMapper.getQuestionBankCount(questionbankid)< 1) {
                returnDel = questionBankMapper.delQuestionBank(questionbankid);
            }
        }catch (Exception e){
            returnDel=-1;
            System.out.println("删除失败原因为："+e.getMessage());
        }
        return returnDel;
    }

    @Override
    public List<QuestionBank> getByQuestionBankid(int questionbankid) {
        List<QuestionBank> questionBankList=questionBankMapper.getByQuestionBankid(questionbankid);
        return questionBankList;
    }

    @Override
    public List<QuestionBank> getAllQuestionBank(QuestionBank questionBank){
        List<QuestionBank> questionBankList = questionBankMapper.getAllQuestionBank(questionBank);
        return questionBankList;
    }

    @Override
    public List<QuestionBank> getByType(String examtypeid, String isquestionrelease) {
        List<QuestionBank> questionBankList = questionBankMapper.getByType(examtypeid,isquestionrelease);
        return null;
    }


    @Override
    public List<QuestionBankEoPage> getQuestionBankWhereAll(QuestionBankEoPage questionBankEoPage) {
        List<QuestionBankEoPage> questionBankList=questionBankMapper.getQuestionBankWhereAll(questionBankEoPage);
        return questionBankList;
    }
}
